<template>
    <el-dialog
      :visible="visible"
      title="编辑学生成绩"
      width="50%"
      @close="handleClose"
    >
      <el-form label-position="left" label-width="20%" class="edit-form">
        <el-form-item label="平均成绩">
          <el-input v-model="localGrade.avgScore"></el-input>
        </el-form-item>
        <el-form-item label="学科数量">
          <el-input v-model="localGrade.subjectCount"></el-input>
        </el-form-item>
        <el-form-item label="挂科数">
          <el-input v-model="localGrade.failureCount"></el-input>
        </el-form-item>
        <el-form-item label="非专业课程数量">
          <el-input v-model="localGrade.nonProfessionalCount"></el-input>
        </el-form-item>
        <el-form-item label="非专业课程平均分数">
          <el-input v-model="localGrade.nonProfesionalCouresScoreAvg"></el-input>
        </el-form-item>
        <el-form-item label="专业课程数量">
          <el-input v-model="localGrade.professionalCount"></el-input>
        </el-form-item>
        <el-form-item label="专业课程平均分数">
          <el-input v-model="localGrade.profesionalCouresScoreAvg"></el-input>
        </el-form-item>
        <el-form-item label="第一学期平均绩点">
          <el-input v-model="localGrade.firstYearOneScore"></el-input>
        </el-form-item>
        <el-form-item label="第二学期平均绩点">
          <el-input v-model="localGrade.firstYearTwoScore"></el-input>
        </el-form-item>
        <el-form-item label="第三学期平均绩点">
          <el-input v-model="localGrade.secondYearOneScore"></el-input>
        </el-form-item>
        <el-form-item label="第四学期平均绩点">
          <el-input v-model="localGrade.secondYearTwoScore"></el-input>
        </el-form-item>
        <el-form-item label="第五学期平均绩点">
          <el-input v-model="localGrade.thirdYearOneScore"></el-input>
        </el-form-item>
        <el-form-item label="第六学期平均绩点">
          <el-input v-model="localGrade.thirdYearTwoScore"></el-input>
        </el-form-item>
        <el-form-item label="第七学期平均绩点">
          <el-input v-model="localGrade.fourthYearOneScore"></el-input>
        </el-form-item>
        <el-form-item label="第八学期平均绩点">
          <el-input v-model="localGrade.fourthYearTwoScore"></el-input>
        </el-form-item>
      </el-form>
      <template #footer>
        <span class="dialog-footer">
          <el-button @click="handleClose">取消</el-button>
          <el-button type="primary" @click="saveEdit">保存</el-button>
        </span>
      </template>
    </el-dialog>
  </template>
  
  <script>
  import { ref, watch } from "vue";
  
  export default {
    props: {
      visible: Boolean,
      currentGrade: Object,
    },
    emits: ["update:visible", "save-grade"],
    setup(props, { emit }) {
      const localGrade = ref({ ...props.currentGrade });
  
      watch(
        () => props.currentGrade,
        (newValue) => {
          localGrade.value = { ...newValue };
        },
        { deep: true }
      );
  
      const handleClose = () => {
        emit("update:visible", false);
      };
  
      const saveEdit = () => {
        emit("save-grade", localGrade.value);
        handleClose();
      };
  
      return {
        localGrade,
        handleClose,
        saveEdit,
      };
    },
  };
  </script>